﻿using System;
using System.Collections.ObjectModel;
using Moq;
using Prompts.PromptServiceProxy;
using Prompts.Service.PromptService;

namespace Test.Prompts.Infrastructure.Fakes
{
    internal class FakePromptSelectionServiceClient
    {
        private readonly Mock<IPromptSelectionService2Client> _mock;
        private object _stateTemp;

        public FakePromptSelectionServiceClient()
        {
            _mock = new Mock<IPromptSelectionService2Client>();
        }

        public void SetupSetPromptSelections(string path, ObservableCollection<PromptSelectionInfo> promptSelections)
        {
            Func<object, bool> interceptStateFunction = o =>
                {
                    _stateTemp = o;
                    return true;
                };

            _mock.Setup(m => m.SetPromptSelectionsAsync(
                path,
                promptSelections,
                It.Is<object>(i => interceptStateFunction(i))));
        }

        public void RaiseSetPromptSelections(string executionId)
        {
            var wrapper = new object[] { executionId };
            var args = new SetPromptSelectionsCompletedEventArgs(wrapper, null, false, _stateTemp);
            _mock.Raise(m => m.SetPromptSelectionsCompleted += null, args);
        }

        public IPromptSelectionService2Client Object
        {
            get { return _mock.Object; }
        }
    }
}
